package soundwave.com.demo.adpater;

import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;

import java.util.ArrayList;

import soundwave.com.demo.test.Imageview_test;

/**
 * Created by xu on 2017/4/15.
 */

public class Viewpager_adapert extends PagerAdapter {
    private ArrayList<Imageview_test>imges;
    private ImageView[]imageViews;

    public Viewpager_adapert(ArrayList<Imageview_test> imges,ImageView[]imageViews) {
        this.imges=imges;
        this.imageViews=imageViews;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }

    @Override
    public int getCount() {
        return imges.size();
    }

    @Override
    public void destroyItem(View container, int position, Object object) {
        ((ViewPager)container).removeView(imageViews[position%imges.size()]);
    }

    @Override
    public Object instantiateItem(View container, int position) {
        try {
            ((ViewPager)container).addView(imageViews[position%imges.size()],0);
        }catch (Exception e){

        }
        return imageViews[position%imges.size()];
    }
}
